Modified pooling to handle cases where output matrix is larger than the input matrix