Remove warnings caused by shadowed 'index' variable

The index variable shadowed a variable in the standard library causing
warnings. Renaming the 'index' variable to 'idx' resolves the issue.