bugfix #3945 pass idx,idx1 by reference instead of static vars

http://code.opencv.org/issues/3945