How to stop current leakage in LED matrix
You are using i2c to communicate with the GPIO expander.

I2C is relatively slow with the result that there will be hundreds of microseconds between the commands to write to device 0x12 and 0x13.

During that time the output of the GPIO expander output at 0x12 will be set to the new data but 0x13 will still be from the the previous data - this can result in unwanted LEDs being lit.

One way to solve this is to write zero to 0x12 to turn off the LEDs, then write 0x13 with new data then write the wanted value to 0x12.

Often when using multiplexed LEDs there can be problems either caused by software delays or just the time that it takes hardware signals to stabilize and will require similar approaches to avoid the problem.