bugfix #3945 pass idx,idx1 by reference instead of static vars
Merge pull request #3312 from berak:b_3945_30