Improved sparse getindex

Now faster and uses less memory in most common cases.
Merge pull request #7131 from mauro3/sparse_indexing2

Improved sparse getindex