By Mariya Gordeyeva and Katya Golubkova

ALMATY/MOSCOW (Reuters) - Kazakhstan's two biggest lenders, Kazkommertsbank (KKB) <KKGB.KZ> and Halyk Bank <HSBK.KZ> <HSBKq.L>, are discussing a merger to create a bank with assets of $27 billion that would dwarf its competitors, two sources familiar with the talks told Reuters.

The two lenders, which both have links to President Nursultan Nazarbayev, account for 37 percent of Kazakhstan's banking system assets.

The new bank would be four times the size of the No. 3 lender by current assets but the merger could involve the write-down of bad assets belonging to Kazkommertsbank, one source who is close to Halyk bank said. This could involve some help from the state, the source said without giving further details.

Halyk, listed both in London and Almaty, has a market capitalization of $1.7 billion, while domestically-listed KKB's market capitalization is about $540 million.

Halyk Bank declined to comment on the matter, while KKB's press office said it was unaware of any merger discussions.

The deal, if agreed, could only take place after May 2017 when Halyk is set to redeem a $638 million Eurobond. The bond's covenants would stand in the way of the merger, the source close to Halyk said.

The idea of the merger, according to that source, has come from within the family of Nazarbayev, whose daughter Dinara together with her husband Timur Kulibayev has a controlling stake in Halyk. Kulibayev could not be reached for comments.

KKB is controlled by local businessman Kenges Rakishev, a son-in-law of Nazarbayev's long-time confidant, Deputy Prime Minister Imangali Tasmagambetov.

Rakishev, who could not be reached for comments on the merger talks, has built his stake up over the last two years. Kazakhstan's sovereign wealth fund Samruk Kazyna also has a minority stake in KKB.

The second source, a banker familiar with the talks, said he had first heard about the potential deal a month ago. He also said that the outstanding bond issue was an obstacle.

The owners of the two banks want to consolidate their market shares through the deal, the banker said.

ASSET CLEAN-UP

If the deal goes through, the bank would be four times larger than No. 3 lender Tsesnabank, and six times as big as the local subsidiary of Russian Sberbank, the No.4 Kazakh lender.

But the deal might require an asset clean-up first. Half of KKB's assets are tied up in a single loan to BTA, a former bank that is now an asset management company which has twice defaulted on its debt.

BTA, once the biggest Kazakh lender, was taken over by Kazakhstan's sovereign wealth fund in 2009 shortly before the first default.

The government said at the time that BTA would have collapsed completely if it had not had a $2 billion cash injection from the fund which then sold it to KKB in 2014 in a deal valuing BTA at $1 billion.

KKB then turned BTA into a distressed asset management company - transferring some of its own bad loans to it - and sold it to Rakishev and another local businessman for just $16,000.

BTA still owes KKB about $7.5 billion and has so far missed no repayments on that debt, but the outlook for them is uncertain.

"Although this loan is classified as performing and KKB's shareholder is involved in overseeing BTA as its ultimate shareholder, BTA's ability to service the much higher repayments from 2019 remains uncertain," rating agency Standard & Poor's said last month as it raised KKB's rating to 'B-' from 'CCC+' but maintained a negative outlook.

Kazakh banks went through a stage of rapid growth in the early 2000s but were among the first victims of the global financial crisis, struggling to repay debt and collect loans.

(Writing by Olzhas Auyezov; editing by Anna Willard)