Fixed possible integer overflow issue when indexing the big matrices