WIP: Refactor _unpack_index.

Addresses comments by @pv:
https://github.com/scipy/scipy/pull/2689#discussion-diff-5670335
https://github.com/scipy/scipy/pull/2689#discussion-diff-5670515
https://github.com/scipy/scipy/pull/2689#discussion-diff-5670621