Fix for #5313: PyArray_AsCArray caused segfault with 3D-arrays

This fix addresses issue #5313 and should now be fixed.
Many thanks to juliantaylor for the tips.
Hmm, this looks right, but the replacement of `m-1` by `m` worries me a bit. Just want to make sure you have checked.