Fixed the indexing problem for the non-mex version of this code (thanks to Natraj Raman).

Fixed the indexing problem for the non-mex version of this code (thanks
to Natraj Raman).