relate field filtered by passing value

Let me describe my problem better:
In the editing form of the Opportunities module I have two related fields that point respectively to the Accounts modules and to my custom ‘Company ESP’ module.
The Company and ‘ESP Company’ modules are related to many to many.
What I would like to do in the Edting view of the Opportunity module is that when I select a value from the relate field ‘Company ESP’ I filter the values of the relate field ‘Company’ according to those chosen in the previous field.

Instead of a relate field for the company module I also thought to use a non-db field as explained in the article http://www.urdhva-tech.com/blogs/filter-by-related-module-s-field.
The problem is that I wouldn’t know how to pass the value of the chosen ‘Company ESP’ field to this last non-db filed.

Any advice?