Cancer patients who took immune therapies such as Merck & Co.’s Keytruda or Bristol-Myers Squibb Co.’s Opdivo showed a greater risk of developing heart problems in a study.