You need to take into account the fact that you're adding one after checking against the length of the array:
if (currentIndex < imageArray.length - 1) {
currentIndex = currentIndex + 1;
}
else {
currentIndex = 0;
}
or
currentIndex += 1;
if (currentIndex >= imageArray.length)
currentIndex = 0;
You really don't need to pass the parameter at all, however, because the function can just use the global variable. (It'd be better not to have one, but since you do, well, you might as well use it.)