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