how to pass variables from one module to another module? I wanted to use apachesolr module along with a field module that is custom written. 

The field module gives the input to 'apachesolr' module instead of the normal search bar. The output is passed through the field module. The output is printed as the field output.

Will module_invoke() be helpful in these cases? 

I want to pass variables from one module to another module like the input and output.
As alternative, you can use also drupal_static() if the value you pass from a module to the other doesn't need to be saved past the page request. When both the modules pass to drupal_static() the same value for the first parameter, they get the same static value.

In the case you use drupal_static(), you must be sure the module that is setting the static variable is executed before the module that reads that value.