Fixed #5147 collapsingbug in einsum

At tests is also included that fails without the fix.
I don't think this second test makes much sense: you are simply checking that the output of calling the same function twice is the same... Actually, you could join these two tests into a single one that looked something like, with your same `x`:

```
y1 = np.einsum('aabb->ab', x)
idx = np.arange(5)
y2 = x[idx[:, None], idx[:, None], idx, idx]
assert_equal(y1, y2)
```

which is a more 'numpythonic' way of doing things.