make max_idx and i of type int