Real Madrid have agreed a deal to sign goalkeeper Diego Lopez from Sevilla on a four-and-a-half-year contract.