If I try to run the code you've shown* with strict and warnings, it does not compile. But both if I leave them off, and if I turn them on and change my $i, $imax; to my ($i, $imax); as it should be (the second actually declares two lexical variables), then the snippet you've provided works correctly for me, so this code does not actually reproduce the problem you are describing. This is why providing a representative Short, Self-Contained, Correct Example is important.
If I had to guess, maybe you're using a variable named $imax somewhere else in your code, and because of this, the $imax you're using in get_max_index is actually not local to that sub, and so some overlap is going wrong there. Always Use strict and warnings!
* Update: Code has been edited, original code that I was referring to is here.