How to pass parameters by reference to a batch?
Alfred is right. You can achieve that by using the $context parameter.

public static function someFunction($a, $b, &amp;$context) {
  // Store data in $context['results'] entry.
  // my_var will keep that value.
  $context['results']['my_var'] = 20;
}