Function for column reduction of matrix