add generateIndexMatrix for the 2d case