Applying filter to the matrix