fix repeated indices in matrix terms