CostMatrix reduction